package socketTest;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Arrays;

//import TestFail.MyRuns1;

/**
 * socket客户端连接
 * 
 * */
public class socketClient {
	static Socket socket=null;  
	BufferedReader reader=null;  
	BufferedWriter writer=null;
	PrintWriter pw=null;
	InputStream is=null;
	BufferedReader reader2=null; 
	/**控制心跳发送*/
	private static volatile boolean bl=true;
	/**控制连续循环*/
	 boolean stop=true;
   /**返回线程类clientrRuns,执行启动线程*/
    clientrRuns getThread(){
		return new clientrRuns();
	}
    public void endBl(){
    	this.bl=false;
    }
    public  void startBl(){
    	this.bl=true;
    }
    public  boolean getBl(){
    	return this.bl;
    }
    
     void socketAction(){  
        
        try {  
        	socket=new Socket("127.0.0.1", 7878);  
        	reader = new BufferedReader(new InputStreamReader(System.in));  
        	reader2=new BufferedReader(new InputStreamReader(socket.getInputStream())); 
        	is=socket.getInputStream();
            OutputStream os = socket.getOutputStream();// 字节输出�?
            pw = new PrintWriter(os);
        	pw.write("33"+"\n");  
        	pw.flush(); 
        	System.out.println("传输");
        	
        	String info="";
        	
        	/*自动忽略\n
        	  boolean b=true;
        	  while(b){
        		info+= reader2.readLine();
        		if(info.endsWith("MNF")){
        			b=false;
        		}
        	}*/
        	
        	 byte[] b1=new byte[20000];
        	int by=0;
        	
        	by=is.read(b1);
             info+=new String(b1);
             String[] s=info.split("MNF");
        	 System.out.println(s[0]+"MNF");
        	 System.out.println("info:"+info.substring(0, info.indexOf("MNF")+4));
        	 System.out.println("接收长度："+(s[0]+"MNF").length()+":"+by);
          
                
              
            
        } catch (Exception e) {  
            e.printStackTrace();  
        } 
    } 
    
    public String  sendTest(String lineString) throws IOException{
    	
    	pw.write(lineString+"\n");  
    	pw.flush(); 
    	
    	String info="";
    	/*boolean b=true;
    	while(b){
    		info+= reader2.readLine();
    		if(info.endsWith("MNF")){
    			b=false;
    		}
    	}*/
    	 byte[] b1=new byte[20000];
        	int by=0;
        	by=is.read(b1);
             info+=new String(b1);
             String[] s=info.split("MNF");
        	 System.out.println(s[0]+"MNF");
        	 System.out.println("info:"+info.substring(0, info.indexOf("MNF")+4));
        	 System.out.println("接收长度："+(s[0]+"MNF").length()+":"+by);
        return info;
    }
    public void  sendEnd() throws IOException{
    	
    	pw.write("end1\n");  
    	pw.flush(); 
    	socket.shutdownOutput();
    	
    	String info="";
    	/*boolean b=true;
    	while(b){
    		info+= reader2.readLine();
    		if(info.endsWith("MNF")){
    			b=false;
    		}
    	}*/
    	byte[] b1=new byte[20000];
    	int by=0;
    	
    	by=is.read(b1);
         info+=new String(b1);
         String[] s=info.split("MNF");
    	 System.out.println(s[0]+"MNF");
    	 System.out.println("info:"+info.substring(0, info.indexOf("MNF")+4));
    	 System.out.println("接收长度："+(s[0]+"MNF").length()+":"+by);
    }
    
}
